library(dplyr) library(tidyr) library(ggplot2) library(ggthemes)
7 października 2017
library(dplyr) library(tidyr) library(ggplot2) library(ggthemes)
mieszkania <- read.csv(file = "data/mieszkania_wroclaw_ceny.csv") %>%
mutate(duze = metraz > 50,
pietro = ifelse(pietro == 0, "parter",
ifelse(pietro == pietro_maks, "ostatnie_pietro",
ifelse(pietro > 15, "wysoko",
ifelse(pietro_maks < 3, "niska_zabudowa", "inne")))),
pietro = factor(pietro),
pokoj = factor(ifelse(n_pokoj > 3, ">3", n_pokoj)))
## Warning: package 'bindrcpp' was built under R version 3.3.2
srednia_cena_pokoje <- mieszkania %>% group_by(n_pokoj) %>% summarise(srednia_cena = mean(cena_m2)) ggplot(srednia_cena_pokoje, aes(x = n_pokoj, y = srednia_cena)) + geom_bar(stat = "identity")
ggplot(mieszkania, aes(x = n_pokoj)) + geom_bar()
ggplot(mieszkania, aes(x = dzielnica, y = ..count..)) + geom_bar(aes(fill = pokoj), position = "stack")
ggplot(mieszkania, aes(x = dzielnica, y = ..count..)) + geom_bar(aes(fill = pokoj), position = "fill")
ggplot(mieszkania, aes(x = dzielnica, y = cena_m2)) + geom_point()
ggplot(mieszkania, aes(x = dzielnica, y = cena_m2, col = duze)) + geom_point()
ggplot(mieszkania, aes(x = dzielnica, y = cena_m2, col = duze)) + geom_point(position = "jitter")
set.seed(1410) ggplot(mieszkania, aes(x = dzielnica, y = cena_m2)) + geom_point(position = "jitter")
Chcemy:
Co jeśli chcemy zobaczyć rozkład punktów w grupach zależnych od liczby pokojów?
ggplot(mieszkania, aes(x = dzielnica, y = cena_m2)) + geom_point(position = "jitter") + facet_wrap(~ pokoj)
ggplot(mieszkania, aes(x = dzielnica, y = cena_m2)) + geom_point(position = "jitter") + facet_wrap(~ pokoj, labeller = label_both)
ggplot(mieszkania, aes(x = dzielnica, y = cena_m2)) + geom_point(position = "jitter") + facet_wrap(~ pokoj + pietro, labeller = label_both)
ggplot(mieszkania, aes(x = dzielnica, y = cena_m2)) + geom_point(position = "jitter") + facet_grid(pietro ~ pokoj, labeller = label_both)
ggplot(mieszkania, aes(x = dzielnica, y = cena_m2)) + geom_boxplot() + facet_wrap(~ pokoj, labeller = label_both)
ggplot(mieszkania, aes(x = dzielnica, y = cena_m2, color = duze)) + geom_point(position = "jitter") + facet_grid(pietro ~ pokoj, labeller = label_both)
ggplot(mieszkania, aes(x = cena_m2)) + geom_density()
ggplot(mieszkania, aes(x = cena_m2, fill = pokoj)) + geom_density()
ggplot(mieszkania, aes(x = cena_m2, fill = pokoj)) + geom_density(alpha = 0.2)
ggplot(mieszkania, aes(x = cena_m2, fill = pokoj)) + geom_density() + facet_wrap(~pokoj, ncol=1)
ggplot(mieszkania, aes(x = cena_m2, fill = pokoj)) + geom_density(adjust = 0.5) + facet_wrap(~pokoj, ncol=1)
ggplot(mieszkania, aes(x = metraz, fill = pokoj)) + geom_density(adjust = 2) + facet_wrap(~pokoj, ncol=1)
load("data/mapa_dzielnic.Rdata")
plot_data <- mieszkania %>%
group_by(dzielnica) %>%
summarise(cena_m2 = mean(cena_m2)) %>%
inner_join(granice_dzielnic, by=c("dzielnica"="id"))
ggplot(plot_data) + geom_polygon(aes(x=long, y=lat, group = dzielnica, fill = cena_m2))
ggplot(plot_data) + geom_polygon(aes(x=long, y=lat, group = dzielnica, fill = cena_m2)) + coord_map()
library(ggthemes)
ggplot(srednia_cena_pokoje, aes(x = n_pokoj, y = srednia_cena, fill = srednia_cena)) + geom_bar(stat = "identity") + scale_fill_gradient2_tableau(palette = "Light Red-Green") + theme_economist_white()
## Warning: Non Lab interpolation is deprecated
ggplot(plot_data) + geom_polygon(aes(x=long, y=lat, group = dzielnica, fill = cena_m2)) + coord_map() + scale_fill_gradient2_tableau() + #skala kolorów z programu tableau theme_fivethirtyeight() #wygląd wykresu wzorowany na fivethirtyeight
## Warning: Non Lab interpolation is deprecated
library(ggbeeswarm) ggplot(mieszkania, aes(x = dzielnica, y = cena_m2, color = duze)) + geom_quasirandom() + facet_grid(pietro ~ pokoj, labeller = label_both)